home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60914 / 60914.xpi / chrome / content / save.js < prev    next >
Text File  |  2010-01-20  |  3KB  |  105 lines

  1.  
  2.  
  3.     var PersonasRotatorBackSave = {
  4.         
  5.         getlibraryfileURI : function () {
  6.             
  7.             var file = Components.classes["@mozilla.org/file/directory_service;1"]
  8.                      .getService(Components.interfaces.nsIProperties)
  9.                      .get("ProfD", Components.interfaces.nsIFile);            
  10.             
  11.             file.append("personasrotator");
  12.             
  13.             file.append("library.rdf");
  14.             
  15.             var ios = Components.classes["@mozilla.org/network/io-service;1"]
  16.                                 .getService(Components.interfaces.nsIIOService);
  17.                                 
  18.             var URL = ios.newFileURI(file);
  19.             
  20.             return URL.spec;
  21.         
  22.             
  23.         },
  24.  
  25.         populateItems : function () {
  26.                         
  27.             var ds=PersonasRotatorRDF.rdfService.GetDataSourceBlocking(PersonasRotatorBackSave.getlibraryfileURI());    
  28.  
  29.             var container=PersonasRotatorRDF.rdfContainerUtils.MakeSeq(ds,PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator:library"));
  30.             
  31.             var genericpersonasseqenumurator=container.GetElements();
  32.             
  33.             var namePredicate = PersonasRotatorRDF.rdfService.GetResource("urn:personasrotator#name");
  34.  
  35.             while (genericpersonasseqenumurator.hasMoreElements()) {
  36.         
  37.                 var collection=genericpersonasseqenumurator.getNext();
  38.                 
  39.                 var nametarget=ds.GetTarget(collection,namePredicate,true);
  40.                 
  41.                 if (nametarget) {
  42.                     
  43.                     var name = nametarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  44.  
  45.                 }
  46.  
  47.                 var newmenuitem=document.createElement("menuitem");
  48.  
  49.                 newmenuitem.setAttribute("label",name);
  50.                 
  51.                 newmenuitem.setAttribute("id",name+"menuitem");
  52.             
  53.                 newmenuitem.setAttribute("class","collection-menuitem");
  54.                 
  55.                 document.getElementById("collistpopup").appendChild(newmenuitem);
  56.         
  57.             }
  58.  
  59.         },
  60.         
  61.         cancelDialog : function () {
  62.  
  63.             return true;
  64.             
  65.         },    
  66.         
  67.         acceptDialog : function () {
  68.         
  69.             if(document.getElementById("collist").selectedIndex==-1) {alert("Please choose a collection to save your persona in");return false;}
  70.             
  71.             var doc=window.arguments[0];
  72.             
  73.             var chosencolname=document.getElementById("collist").selectedItem.getAttribute("label");
  74.             
  75.             window.opener.PersonasRotator.savepreview(chosencolname,window.opener.PersonasRotator.retrievetabpersonaimagefrompersonasrotator(doc),doc);
  76.         
  77.             return true;
  78.             
  79.         },
  80.         
  81.         handleWindowLoad :function(event){
  82.         
  83.             PersonasRotatorBackSave.populateItems();
  84.             
  85.             document.getElementById("savepersonabutton").addEventListener("command",PersonasRotatorBackSave.handleSaveBackButtonCommand,false);
  86.             
  87.             document.getElementById("cancelsavepersonabutton").addEventListener("command",PersonasRotatorBackSave.cancelSaveBackButtonCommand,false);
  88.         
  89.         },
  90.         
  91.         handleSaveBackButtonCommand:function(event){
  92.         
  93.             if(PersonasRotatorBackSave.acceptDialog()) window.close();
  94.         
  95.         },
  96.         
  97.         cancelSaveBackButtonCommand:function(event){
  98.         
  99.             window.close();
  100.         
  101.         }
  102.  
  103.     }
  104.             
  105.     window.addEventListener("load",PersonasRotatorBackSave.handleWindowLoad,false);